﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using Tanmia.Basis;
using NHibernate.Criterion;
using NHibernate;

namespace Tanmia.NHibernate
{
    public class PersonRepository : Repository<Person>
    {
        public IList<Person> Gets(Item item, Color color)
        {
            ISession session = SessionFactory.Session;

            var subQuery = QueryOver.Of<DiscriminatedItem>()
                .Where(x => x.Item.ItemID == item.ItemID)
                .Where(x => x.Color.ColorID == color.ColorID)
                .Select(x => x.Manufacturer.PersonID);

            var result = session.QueryOver<Person>()
                .WithSubquery.WhereProperty(x => x.PersonID).In(subQuery)
                .List<Person>();

            return result;
        }
    }
}
